<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>
<style>
.ordercount{
	width:100%;
    display: inline-flex;
}
.samestatic{
	width:309px;
	height:150px;
	margin-top:10px;
	margin-left:77px;
}
.samestatic:nth-child(1){
	margin-left:0px;
}
.ordersty{
	background:#1f95ef;
}
.balance{
	background:#45b854;
}
.customer{
	background:#f86b67;
}
.sametitle{
	color: #fff;
    font-size: 16px;
    margin-left: 20px;
    margin-top: 10px;
}
.sameorderinfo{
	color: #fff;
    margin-left: 35px;
    line-height:20px;
}
.summer-datagrid-cell{
	text-align:center;
}
.top-batch{
    width:80px;
	height:34px;
	text-align:center;
}
/*******批量备注*******/
.remarkcon{
    height: 77px;
    background: #fff;
    border: solid 1px #e1e6eb;
    border-bottom: 0;
}
.remarkbut{
	width:114px;
	height:34px;
	border:solid 1px #f86b67;
	line-height:34px;
	text-align:center;
	color:#f86b67;
	margin:20px;
	cursor:pointer;
}
.smallremark{
	color: #1f95ef;
    font-size: 10px;
    margin-left: 7px;
}
.copybut{
	color:#0474c8;
	margin-left: 5px;
	cursor:pointer;
    margin-right: 8px;
}
/***按钮选中态****/
.pitchbut{
	background:#f86b67;
	color:#fff;
}
/*******表格样式*********/
.proleft{
  float:left;
  margin-top: 2px;
  width: 33%;
}
.proleft>img{
  width:84px;
  height:84px;
}
.proright{
  float:left;
  margin-left:2px;
  margin-top: 2px;
  text-align: left;
      width: 66%;
  
}
.sametr{
	height: 110px;
    border-bottom: solid 1px #999;
}
.summer-top{
	padding:0px !important;
}
/*******head******/
.headcon{
    width: 100%;
    border-bottom: solid 1px #0288d1;
}
.top-batch{
	width:100%;
	line-height:34px;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    
</div>
<div class="headcon">
<table class="summer-datagrid" style="width:auto">
	
	    <thead class="orderhead">
	    	<tr>
	    		<th style="width:100px;"><div class="top-batch  pitchbut">今日精选</div></th>
	    		<th  style="width:100px;"><div class="top-batch"><a id="tohot" href="javascript:;">爆品分享</a></div></th>
	    		<th  style="width:120px;"><div class="top-batch"><a id="tosharepyq" href="javascript:;">一键发朋友圈</a></div></th>
	    	</tr>
	    </thead>		
	</table>
</div>
<div class="search-field">
	<span class="field-cont">
        <span class="field-cont-title">商品名称</span>
        <input type="text" class="summer-input" id="goodsName"/>
    </span>
    <span class="field-cont">
        <span class="field-cont-title">商品类型</span>
        <input type="text" class="summer-input" id="spuPlatform"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">商品分类</span>
        <input type="text" id="categoryId" name="categoryId" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
        
    </span><br/>
   
     <span class="field-cont">
        <span class="field-cont-title">是否爆款</span>
        <input type="text" class="summer-input" id="isHot"/>
        <input type="hidden" class="summer-input" id="isJingping" value="0"/>
    </span><br/>
     <span class="field-cont">
        <span class="field-cont-title">佣金排序</span>
        <input type="text" class="summer-input" id="wlCommission"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">佣金比例排序</span>
        <input type="text" class="summer-input" id="wlCommissionShare"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">时间</span>
        <input type="text" class="summer-input" id="createTime"/>
    </span>

    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

	<table class="summer-datagrid" style="width:auto">
		
	    <thead class="orderhead">
	    	<tr>
	    		<th style="width:30%;"><div class="summer-datagrid-cell" style="padding: 9px 8px;"><a id="tomain" href="javascript:;">精选列表</a></div></th>
	    		<th style="width:30%;"><div class="summer-datagrid-cell   pitchbut" style="padding: 9px 8px;"><a id="togoods" href="javascript:;">商品列表</a></div></th>
	    	</tr>
	    </thead>		
	</table>
	
	<div class="remarkcon">
		<div class="remarkbut" id="batchAdd"><a>批量设置精选</a></div>
	</div>
	
	<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="10%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">		    
	    <thead>
		     <tr>
		    <th><div class="summer-datagrid-cell"><input type="checkbox" id="addBatchAll"></div></th>
		    <th><div class="summer-datagrid-cell">名称</div></th>
		    <th><div class="summer-datagrid-cell">图片</div></th>
		    <th><div class="summer-datagrid-cell">类型</div></th>
		    <th><div class="summer-datagrid-cell">分类</div></th>
		    <th><div class="summer-datagrid-cell">价钱（原价、券后价、佣金数）</div></th>
		    <th><div class="summer-datagrid-cell">时间</div></th>
		    <th><div class="summer-datagrid-cell">操作</div></th>
			 </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		INIT_MAIN: basePath + '${common_url}init',
		INIT_HOT: basePath + '${common_url}initHot',
		INIT_SHARE: basePath + '${common_url}initShare',
		DEL: basePath + '${common_url}deljx',
		GOODS_LIST: basePath + '${common_url}goodsList',
		REORDER: basePath + '${common_url}reorder',
		INIT_GOODS_LIST: basePath + '${common_url}initGoods',
		GET_CATEGORY_ID: basePath + '${common_url}getGoodsCategory',
		SET_JX: basePath + '${common_url}setJx',
		BATCH_SET_JX: basePath + '${common_url}batchSetJx'
	};
	
    var  wlcReorder,
   		 wlcsReorder,
    	 timeReorder,
    	 permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {   	
    	 $('#spuPlatform').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_SPU_PLATFORM'
         });
    	 $('#isHot').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_IS_HOT'
         });
    	 //T_DM_T_GOODS_SPU_WL_COMMISSION
    	 $('#wlCommission').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_WL_COMMISSION'
         });
    	 //T_DM_T_GOODS_SPU_WL_COMMISSION_SHARE
    	 $('#wlCommissionShare').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_WL_COMMISSION_SHARE'
         });
    	 //T_DM_T_GOODS_SPU_CREATE_TIME
    	 $('#createTime').combobox({
             valueField : 'code',
             textField : 'name',
             url : COMMON_URL.getCode + '?type=T_DM_T_GOODS_SPU_CREATE_TIME'
         });
    	 
    	//初始化下拉选项  商品所属公司
    	 $('#categoryId').combobox({
             url : CONST_URL.GET_CATEGORY_ID, 
             valueField : 'id',
             async:false,
             textField : 'name'
         });

    	//设置精选
 		$('#t-wrap').on(
 				'click',
 				'a[data-permit="${name_english}:setJx"]',
 				function() {
 					var $this = $(this), id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
 					$.sdialog({
 						type : 'confirm',
 						msg : '您确定要设置精选吗?',
 						onConfirm : function(result) {
 							if (result) {
 								$.sajax({
 									url : CONST_URL.SET_JX + "?id=" + id,
 									onLoadSuccess : function() {
 										$.stip({
 											type : 'ok',//显示类型 有info、 ok、 danger
 											text : '设置成功！'
 										});
 										reloadTable();
 									}
 								});

 							}
 						}
 					});
 				});
    	//跳转爆款页
    	$('#tohot').on('click',toHot);
    	//跳转分享朋友圈页
    	$('#tosharepyq').on('click',toShare);
    	$('#togoods').on('click',toGoodsList);
    	$('#tomain').on('click',tomain);
    	/************/
       
        $('#search').on('click', reloadTable);
        $('#reset').on('click', function() {
			//重置文本框的值
			$('#goodsName').val('');
			$('#spuPlatform').combobox('clear');
			$('#categoryId').combobox('clear');
			$('#isJingping').val('');
			$('#isHot').combobox('clear');
			$('#wlCommission').combobox('clear');
			$('#wlCommissionShare').combobox('clear');
			$('#createTime').combobox('clear');
			reloadTable();
		});
        
      //选中顶部勾选框
      $('#addBatchAll').on('click',checkAll);
      $('#batchAdd').on('click',tobatchAdd);
		createTable();
	});
	// 重新加载表格
	function reloadTable() {
		wlcReorder = $('#wlCommission').combobox('getValue');	
		wlcsReorder = $('#wlCommissionShare').combobox('getValue');
		timeReorder = $('#createTime').combobox('getValue');
		createTable(wlcReorder,wlcsReorder,timeReorder);
		$('#dataList').datagrid('reload', {
			ajax : {
				param : {
					"goodsName": trimSpace($('#goodsName').val()),
					"spuPlatform":$('#spuPlatform').combobox('getValue'),
					"isJingping": trimSpace($('#isJingping').val()),
					"categoryId":$('#categoryId').combobox('getValue'),
					"isHot":$('#isHot').combobox('getValue')/* ,
					"wlCommission":$('#wlCommission').combobox('getValue'),
					"wlCommissionShare":$('#wlCommissionShare').combobox('getValue'),
					"createTime":$('#createTime').combobox('getValue') */
				}
			}
		});
	}
	
	//创建表格
	function createTable(wlcReorder,wlcsReorder,timeReorder) {
		
		$('#dataList')
				.datagrid(
						{
							ajax : {
								url : CONST_URL.GOODS_LIST+"?wlcReorder="+wlcReorder+"&wlcsReorder="+wlcsReorder+"&timeReorder="+timeReorder,
								param : {	
									"goodsName": trimSpace($('#goodsName').val()),
									"spuPlatform":$('#spuPlatform').combobox('getValue'),
									"isJingping": trimSpace($('#isJingping').val()),
									"categoryId":$('#categoryId').combobox('getValue'),
									"isHot":$('#isHot').combobox('getValue')/* ,
									"wlCommission":$('#wlCommission').combobox('getValue'),
									"wlCommissionShare":$('#wlCommissionShare').combobox('getValue'),
									"createTime":$('#createTime').combobox('getValue') */
								},
								success : function(data) { //成功 
									alert("Data Saved: " + msg);
								}
							},
							columns : [
									{
										field : 'id',
										hidden : true
									},
									{
										render : function(rowData){
											return '<input type="checkbox" id="id" name="id" value="'+rowData.id+'">';
										}
									},
									{
										field : 'goodsName'
									},
									{
										render : function(rowData){
											return '<img width="100" height="100" src="'+rowData.mainImageUrl+'">';
										}
									},
									{
										field : 'spuPlatform'
									},
									{
										field : 'categoryId'
									},
									{
										render : function(rowData){
											return '<p>原价：'+rowData.wlPrice+'</p><br/>'
												  +'<p>券后价：'+rowData.conPrice+'</p><br/>'
												  +'<p>佣金：'+rowData.wlCommission+'</p>';
										}
									},
									{
										field : 'createTime'
									},
									{
										render : function(rowData) {
											return $.funcbar({
														data : permission, //请求的数据
														type : 'text', //类型
														display : 1, //显示数量
														permit : [
																'${name_english}:setJx'
																 ]
													//需要的权限按钮
													});
										}
									}

							]
						});
	}
	
	
	function tobatchAdd() {
		var id = $("input[name='id']:checked").serialize();
		$.sdialog({
			type : 'confirm',
			msg : '您确定要设置精选吗?',
			onConfirm : function(result) {
				if (result) {
					$.sajax({
						url : CONST_URL.BATCH_SET_JX + "?id=" + id,
						onLoadSuccess : function() {
							$.stip({
								type : 'ok',//显示类型 有info、 ok、 danger
								text : '设置成功！'
							});
							reloadTable();
						}
					});

				}
			}
		});

	}
	function checkAll() {
		$("[name='id']").attr("checked", 'true');//全选 
	}

	//跳转代发货页面
	function toHot() {
		window.location.href = CONST_URL.INIT_HOT;
	}
	function toShare() {
		window.location.href = CONST_URL.INIT_SHARE;
	}
	function toGoodsList() {
		window.location.href = CONST_URL.INIT_GOODS_LIST;
	}
	function tomain() {
		window.location.href = CONST_URL.INIT_MAIN;
	}
</script>
</body>
</html>